<?php

$app->group('/blue', function () use ($app, $c, $redis) {
    //$app->applyHook('blue.before');
    $app->get('/', function () use ($app, $c) {
        //$page = (int)$app->request->get('page', 1);
        //$size=1;
        //$nodeTable = $c['Blue.Table.Node'];
        //$nodeCategoryTable = $c['Blue.Table.NodeCategory'];
        //$categoryTable = $c['Blue.Table.Category'];

        //$sql = new \Zend\Db\Sql\Sql($nodeTable->getAdapter());
        /*
        $select = $sql->select()
            ->from(array('a' => $nodeTable->getTable()))
            ->join(array('b' => $nodeCategoryTable->getTable()), 'a.id=b.node_id', array())
            ->order('a.post_at desc');
        */
        /*
        $nodes=array();
        $pages=array();

        $total=$sql->select()->from($nodeTable->getTable())->columns(array('total'=>new \Zend\Db\Sql\Expression('count(1)')));
        $statement = $sql->prepareStatementForSqlObject($total);
        $results = $statement->execute();
        $totalItems=intval($results->current()['total']);
        if($totalItems>0){
            $totalPages=ceil(($totalItems*1.0)/1);
            $page=min($totalPages,max($page,1));
            $select = $sql->select()
                      ->from($nodeTable->getTable())
                      ->order('id desc')->limit($size)->offset(($page-1)*$size);
            $statement=$sql->prepareStatementForSqlObject($select);
            $nodes=$statement->execute();
            $pagination = new \Hengha\Util\Pagination($totalItems, $page, $size);
            $offset = $pagination->offset();
            $limit = $pagination->limit();
            $pages = $pagination->build();    
        }
        */
        
        //$paginator = new \Zend\Paginator\Paginator(new \Zend\Paginator\Adapter\DbSelect($select, $nodeTable->getAdapter()));
        //$paginator->setCurrentPageNumber($page);
        //$paginator->setItemCountPerPage(1);
        //$app->render('blue/index.html',array('page'=>$page,'items'=>$nodes,'pages'=>$pages));
        $app->render('blue/index.html');
    })->name('blue-home');
    include(APP_ROOT . '/routes/blue/categories.php');
    include(APP_ROOT . '/routes/blue/nodes.php');
});
